package com.xl.sst.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.xl.sst.biz.ShoppingCartBiz;
import com.xl.sst.vo.Goods;
import com.xl.sst.vo.ShoppingCart;

/*
 * 购物车处理层
 * yue
 */
@Controller
@RequestMapping("/view")
public class ShoppingCartController {
	@Resource
	private ShoppingCartBiz shoppingCartBiz;
	public ShoppingCartBiz getShoppingCartBiz() {
		return shoppingCartBiz;
	}
	public void setShoppingCartBiz(ShoppingCartBiz shoppingCartBiz) {
		this.shoppingCartBiz = shoppingCartBiz;
	}
	//添加商品到购物车
	@RequestMapping("/CartAdd.do")
	public String  CartAdd(ShoppingCart c){
		if(shoppingCartBiz.CartAdd(c)){
			return "添加成功！";
		}else{
			return "添加失败！";
		}	
	}
	//修改购物车
	@RequestMapping("/CartUpdate.do")
	public String  CartUpdate(ShoppingCart c){
		if(shoppingCartBiz.CartUpdate(c)){
			return "修改成功！";
		}else{
			return "修改失败！";
		}	
	}
	//删除购物车里面信息
	@RequestMapping("/CartDelete.do")
	public String  CartDelete(ShoppingCart c){
		int i=shoppingCartBiz.CartDelete(c);
		if(i>=1){
			return "删除成功！";
		}else{
			return "删除失败！";
		}	
	}
	//查询购物车里面信息
	@RequestMapping("/CartSelect.do")
	public String  CartSelect(ShoppingCart c,Map<String,Object> m){
		List<ShoppingCart> list=shoppingCartBiz.CartSelect(c);
		//获取购物车里面的商品
		List<Goods> listGoods=new ArrayList<Goods>();
		for (ShoppingCart s : list) {
			listGoods.add(shoppingCartBiz.selectGoodsById(s.getGoods_id()));
		}
		m.put("listGoods", listGoods);
		m.put("CartSelect", list);
		return "shoppingCart.jsp";
		
	}
}
